const express = require('express')
const app = express();

const expressWs = require("express-ws")
const wsInstance = expressWs(app);

app.ws('/connect',(ws) => {
    ws.on("open",function(){
        console.log("连接成功");
    });
    ws.on("message",function(event){
        console.log("消息：",wsInstance.getWss().clients.size);
        // chatAry.push(JSON.parse(event));
        // console.log("clients",wsInstance.getWss().clients);
        wsInstance.getWss().clients.forEach((e) => {
            e.send("服务器说");
        })
    });
})

app.listen(3004, () => {
    console.log('success in port 3004，服务已经跑起来啦');
})